﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BonsaiScrum.Core.Domain
{
    public class Manager : IRole
    {
        public Manager() { }
        public Manager(User actor)
        {
            Actor = actor;
        }

        public PermissionLevel PermissionLevel
        {
            get { return PermissionLevel.Manager; }
        }

        public User Actor { get; private set; }

        public Project CreateNewProject(string projectName, string projectDescription)
        {
            MakeSureActorIsAvailable();

            return new Project(projectName, projectDescription, Actor.GetRole<ScrumMaster>());
        }

        public Sprint CreateNewSprint(DateTime startdate, DateTime enddate, string sprintDescription, int project)
        {
            MakeSureActorIsAvailable();

            return new Sprint(startdate, enddate, sprintDescription, project, Actor.GetRole<Manager>());
        }

        public Sprint UpdateSprint(DateTime startdate, DateTime enddate, string sprintDescription)
        {
            MakeSureActorIsAvailable();
            
            return new Sprint(startdate, enddate, sprintDescription);
        }

        internal void Drop(Project project)
        {
            project.Drop();
        }

        private void MakeSureActorIsAvailable()
        {
            if (Actor == null)
                throw new NullReferenceException("An actor must be present to perform this task.");
        }
    }
}
